/**
 * Draw chart with highcharts Last modified: Kevin MOU
 */
try {
	"use strict";
	
	define(['js/hc_theme' + $E.jsv, 'js/hc_bg' + $E.jsv], function(Theme, Bg) {

		var font = {
			title : 'bold 14px Lucida Grande, Lucida Sans Unicode, Verdana, Arial, Helvetica, sans-serif',
			subTitle : '12px Lucida Grande, Lucida Sans Unicode, Verdana, Arial, Helvetica, sans-serif'
		}, 
				
		defaultOptions = {
			//colors: ['#7cb5ec', '#434348', '#90ed7d', '#f7a35c', '#8085e9', '#f15c80', '#e4d354', '#2b908f', '#f45b5b', '#91e8e1'],
			lang : {
				printChart : '打印',
				downloadJPEG : "下载为JPEG",
				downloadPDF : "下载为PDF",
				downloadPNG : "下载为PNG",
				downloadSVG : '下载为SVG',
				resetZoom : '取消放大',
				resetZoomTitle : '恢复至原始尺寸1:1',
				months : [ '1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月' ],
				shortMonths : [ '1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月' ],
				weekdays : [ '星期一 ', '星期二', '星期三', '星期四', '星期五', '星期六', '星期日' ]
			}
		};
		
		/**
		 * 绘制线图
		 * @param ctl
		 * @param categories
		 * @param series
		 * @param custOptions
		 * @param config
		 * @param callback
		 * @param container
		 */
		line = function(ctl, categories, series, custOptions, config, callback, container) {
			var options = {
				chart : {
					reflow: true,
					margin: config.margin,
					spacing : config.spacing || [ 8, 5, 0, 5 ]
				},
				title : {
					text : config.title,
					style : {
						font : font.title
					}
				},
				subtitle : {
					text : config.subTitle,
					style : {
						font : font.subTitle
					}
				},
				exporting : config.exporting,
				credits : false,
				xAxis : [ {
					categories : categories,
					type: 'datetime',
					labels: {
		                format: config.xFormat || ''
		            }
				} ],
				yAxis : {
					title : {
						text : config.yTitle
					},
					min : 0,
					labels: {
		                format: config.yFormat || ''
		            },
					plotLines : [ {
						value : 0,
						width : 1,
						color : '#808080'
					} ]
				},
				tooltip : {
					valueSuffix : config.unit
				},
				legend : {
					//layout : 'vertical',
					//align : 'right',
					//verticalAlign : 'middle',
					//borderWidth : 0,
					enabled : config.legend
				},
				plotOptions: {
		            series: {
		                cursor: 'pointer',
		                stickyTracking: false,
		                events : {
		                	click : function(event) {
		                		if ($.isFunction(callback))
		                			callback({
										CATEGORY: event.point.category,
										NAME: event.point.series.name,
										VALUE: event.point.y
		                			});
		                		
		                	}
		                }
	                }
		        },
				series : series
			};
			
			var op = Highcharts.merge(true, options, custOptions);
			console.group('[' + ctl.id + '] line chart');
			console.log('theme: ' + (config.theme || 'empty') + ', bg: ' + (config.bgStyle || 'empty'));
			console.log(op);
			console.groupEnd();
			container.highcharts(op, function(chart) {
				if (!chart.renderer.forExport) {
					container.data('chartData', chart.series);
				}
			});
		},
		
		/**
		 * 绘制柱状图
		 * @param ctl
		 * @param categories
		 * @param series
		 * @param custOptions
		 * @param config
		 * @param callback
		 * @param container
		 */
		column = function(ctl, categories, series, custOptions, config, callback, container) {
			var options = {
				chart : {
					type : 'column',
					reflow: true,
					margin: config.margin,
					spacing : config.spacing || [ 8, 0, 0, 0 ]
				},
				title : {
					text : config.title,
					style : {
						font : font.title
					}
				},
				subtitle : {
					text : config.subTitle,
					style : {
						font : font.subTitle
					}
				},
				exporting : config.exporting,
				credits : false,
				xAxis : {
					categories : categories,
					crosshair : true,
					labels: {
		                format: config.xFormat || ''
		            }
				},
				yAxis : {
					min : 0,
					title : {
						text : config.yTitle
					},
					labels: {
		                format: config.yFormat || ''
		            }
				},
				tooltip : {
					headerFormat : '<span style="font-size:10px">{point.key}</span><table>',
					pointFormat : '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' + '<td style="padding:0"><b>{point.y} ' + config.unit + '</b></td></tr>',
					footerFormat : '</table>',
					shared : true,
					useHTML : true
				},
				legend : {
					//layout : 'vertical',
					//align : 'right',
					//verticalAlign : 'middle',
					//borderWidth : 0,
					enabled : config.legend
				},
				plotOptions : {
					column : {
						pointPadding : 0.2,
						borderWidth : 0,
						events : {
							click : function(event) {
								//console.log(event)
								if ($.isFunction(callback))
									callback({
										CATEGORY: event.point.category,
										NAME: event.point.series.name,
										VALUE: event.point.y
									});
							}
						}
					}
				},
				series : series
			};
			
			var op = Highcharts.merge(true, options, custOptions);
			console.group('[' + ctl.id + '] column chart');
			console.log('theme: ' + (config.theme || 'empty') + ', bg: ' + (config.bgStyle || 'empty'));
			console.log(op);
			console.groupEnd();
			container.highcharts(op, function(chart) {
				if (!chart.renderer.forExport) {
					container.data('chartData', chart.series);
				}
			});
		},
		
		/**
		 * 绘制三轴对数据图
		 * @param ctl
		 * @param categories
		 * @param series
		 * @param custOptions
		 * @param config
		 * @param callback
		 * @param container
		 */
		lineColumn = function(ctl, categories, series, custOptions, config, callback, container) {
			var comdata = [{
				name : series[0].name,
				type : 'spline',
				reflow: true,
				data : series[0].data,
				tooltip : {
					valueSuffix : config.unit
				},
				yAxis : 1,
			}];
			for(var i=1; i<series.length; i++) {
				comdata.push({
					name : series[i].name,
					type : 'column',
					data : series[i].data,
					tooltip : {
						valueSuffix : config.unit2
					}
				})
			}
			var options = {
				chart : {
					zoomType : 'xy',
					margin: config.margin,
					spacing : config.spacing || [ 8, 0, 0, 0 ]
				},
				title : {
					text : config.title,
					style : {
						font : font.title
					}
				},
				subtitle : {
					text : config.subTitle,
					style : {
						font : font.subTitle
					}
				},
				exporting : config.exporting,
				credits : false,
				xAxis : [ {
					categories : categories,
					crosshair : true,
					labels : {
						format : config.xFormat || ''
					}
				} ],
				yAxis : [ { 
					// Primary yAxis
					labels : {
						format : config.yFormat || '',
					},
					min : 0,
					title : {
						text : config.yTitle,
					}
				}, { 
					// Secondary yAxis
					labels : {
						format : config.yFormat2 || '',
					},
					title : {
						text : config.yTitle2,
					},
					opposite : true
				} ],
				tooltip : {
					shared : true
				},
				plotOptions : {
					column : {
						events : {
							click : function(event) {
								// console.log(event)
								if ($.isFunction(callback))
									callback({
										CATEGORY : event.point.category,
										VALUE : event.point.y
									});
							}
						}
					}
				},
				legend : {
					// layout : 'vertical',
					// align : 'right',
					// verticalAlign : 'middle',
					// borderWidth : 0,
					enabled : config.legend
				},
				series : comdata 
			};
			var op = Highcharts.merge(true, options, custOptions);
			console.group('[' + ctl.id + '] lineColumn chart');
			console.log('theme: ' + (config.theme || 'empty') + ', bg: ' + (config.bgStyle || 'empty'));
			console.log(op);
			console.groupEnd();
			container.highcharts(op, function(chart) {
				if (!chart.renderer.forExport) {
					container.data('chartData', chart.series);
				}
			});
		},
		
		/**
		 * 绘制重叠柱状图
		 * @param ctl
		 * @param categories
		 * @param series
		 * @param custOptions
		 * @param config
		 * @param callback
		 * @param container
		 */
		fixedPlacement = function(ctl, categories, series, custOptions, config, callback, container) {
			var comdata = [{
					name : series[0].name,
					color: 'rgba(165,170,217,1)',
					data : series[0].data,
					pointPadding: 0.3,
		            pointPlacement: -0.2
				}, {
		            name: series[1].name,
		            color: 'rgba(126,86,134,.9)',
		            data: series[1].data,
		            pointPadding: 0.4,
		            pointPlacement: -0.2
		        }]
			var options = {
				chart : {
					reflow: true,
					type : 'column'
				},
				title : {
					text : config.title,
					style : {
						font : font.title
					}
				},
				xAxis : {
					categories : categories
				},
				yAxis : [ {
					min : 0,
					title : {
						text : config.yTitle,
					}
				} ],
				legend : {
					shadow : false
				},
				tooltip : {
					shared : true
				},
				plotOptions : {
					column : {
						grouping : false,
						shadow : false,
						borderWidth : 0
					}
				},
				series : comdata 
			};
			var op = Highcharts.merge(true, options, custOptions);
			console.group('[' + ctl.id + '] fixedPlacement chart');
			console.log('theme: ' + (config.theme || 'empty') + ', bg: ' + (config.bgStyle || 'empty'));
			console.log(op);
			console.groupEnd();
			container.highcharts(op, function(chart) {
				if (!chart.renderer.forExport) {
					container.data('chartData', chart.series);
				}
			});
		},
		
		/**
		 * 绘制条状图
		 * @param ctl
		 * @param categories
		 * @param series
		 * @param custOptions
		 * @param config
		 * @param callback
		 * @param container
		 */
		bar = function(ctl, categories, series, custOptions, config, callback, container) {
			var options = {
				chart : {
					type : 'bar',
					margin: config.margin,
					spacing : config.spacing || [ 8, 5, 0, 5 ]
				},
				title : {
					text : config.title,
					style : {
						font : font.title
					}
				},
				subtitle : {
					text : config.subTitle,
					style : {
						font : font.subTitle
					}
				},
				exporting : config.exporting,
				credits : false,
				xAxis : {
					categories : categories,
					title : {
						text : null
					},
					label : {
						format : config.xFormat || ''
					}
				},
				yAxis : {
					min : 0,
					title : {
						text : config.yTitle,
						align : 'high'
					},
					labels : {
						overflow : 'justify',
						format : config.yFormat || ''
					}
				},
				tooltip : {
					valueSuffix : ' ' + config.unit
				},
				plotOptions : {
					bar : {
						dataLabels : {
							enabled : true
						},
						events : {
							click : function(event) {
								// console.log(event);
								if ($.isFunction(callback))
									callback({
										CATEGORY : event.point.category,
										NAME : event.point.series.name,
										VALUE : event.point.y
									})
							}
						}
					}
				},
				legend : {
					layout : 'vertical',
					align : 'right',
					verticalAlign : 'top',
					x : -40,
					y : 80,
					floating : true,
					borderWidth : 1,
					backgroundColor : ((Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF'),
					shadow : true
				},
				series : series
			};
			
			var op = Highcharts.merge(true, options, custOptions);
			console.group('[' + ctl.id + '] bar chart');
			console.log('theme: ' + (config.theme || 'empty') + ', bg: ' + (config.bgStyle || 'empty'));
			console.log(op);
			console.groupEnd();
			container.highcharts(op, function(chart) {
				if (!chart.renderer.forExport) {
					container.data('chartData', chart.series);
				}
			});
		},
		
		/**
		 * 绘制饼图
		 * @param ctl
		 * @param data
		 * @param custOptions
		 * @param config
		 * @param callback
		 * @param container
		 */
		pie = function(ctl, data, custOptions, config, callback, container) {
			var chart = {
					type : 'pie',
					options3d : {
						enabled : config.depth > 0,
						alpha : config.alpha,
						beta : config.beta
					}
				};
			if (config.margin)
				chart.margin = config.margin;
			if (config.spacing)
				chart.spacing = config.spacing;
				
			var options = {
				chart : chart,
				title : {
					text : config.title,
					style : {
						font : font.title
					}
				},
				subtitle : {
					text : config.subTitle,
					style : {
						font : font.subTitle
					}
				},
				exporting : config.exporting,
				credits : false,
				tooltip : {
					pointFormat : config.name + ': ({point.y}' + config.unit + ')<b>{point.percentage:.2f}%</b><br/>'
				},
				plotOptions : {
					pie : {
	                    allowPointSelect: true,
	                    cursor: 'pointer',
	                    dataLabels: {
	                        enabled: false
	                    },
	                    showInLegend: true,
						events : {
							click : function(event) {
								//console.log(event);
								if ($.isFunction(callback))
									callback({
										NAME: event.point.name,
										VALUE: event.point.y
									});
							}
						}
					}
				},
				series : [ {
					name : config.name,
					data : data
				} ]
			};
			
			var op = Highcharts.merge(true, options, custOptions);
			console.group('[' + ctl.id + '] pie chart');
			console.log('theme: ' + (config.theme || 'empty') + ', bg: ' + (config.bgStyle || 'empty'));
			console.log(op);
			console.groupEnd();
			container.highcharts(op, function(chart) {
				if (!chart.renderer.forExport) {
					container.data('chartData', chart.series[0]);
				}
			});
		},
		
		gauges = function(ctl, data, bands, custOptions, config, callback, container) {
			var options = {
				chart : {
					type : 'gauge',
					margin: config.margin || [35, 15, 15, 15],
					spacing : config.spacing || [ 8, 5, 8, 5 ]
				},
				title : {
					text : config.title,
					style : {
						font : font.title
					}
				},
				exporting : config.exporting,
				credits : false,
				pane : {
					size : '100%',
					startAngle : -150,
					endAngle : 150,
					background : [ {
						backgroundColor : {
							linearGradient : {
								x1 : 0,
								y1 : 0,
								x2 : 0,
								y2 : 1
							},
							stops : [ [ 0, '#FFF' ], [ 1, '#333' ] ]
						},
						borderWidth : 0,
						outerRadius : '109%'
					}, {
						backgroundColor : {
							linearGradient : {
								x1 : 0,
								y1 : 0,
								x2 : 0,
								y2 : 1
							},
							stops : [ [ 0, '#333' ], [ 1, '#FFF' ] ]
						},
						borderWidth : 1,
						outerRadius : '107%'
					}, {
					}, {
					} ]
				},
				yAxis : {
					min : config.min,
					max : config.max,

					minorTickInterval : 'auto',
					minorTickWidth : 1,
					minorTickLength : 10,
					minorTickPosition : 'inside',
					minorTickColor : '#666',

					tickPixelInterval : 30,
					tickWidth : 2,
					tickPosition : 'inside',
					tickLength : 10,
					tickColor : '#666',
					labels : {
						step : 2,
						rotation : 'auto',
						format : config.yFormat || ''
					},
					title : {
						text : config.showLabel ? config.unit : ''
					},
					plotBands : bands
				},
				plotOptions : {
					gauge : {
						dataLabels : {
							enabled : config.showLabel
						},
						events : {
							click : function(event) {
								if ($.isFunction(callback))
									callback(event.series.point.y);
							}
						}
					}
				},
				series : [ {
					name : config.name,
					data : [ data ],
					tooltip : {
						valueSuffix : ' ' + config.unit
					}
				} ]
			}
			
			var op = Highcharts.merge(true, options, custOptions);
			console.group('[' + ctl.id + '] gauges chart');
			console.log('theme: ' + (config.theme || 'empty') + ', bg: ' + (config.bgStyle || 'empty'));
			console.log(op);
			console.groupEnd();
			container.highcharts(op, function(chart) {
				if (!chart.renderer.forExport) {
					container.data('chartData', chart.series[0].points[0]);
				}
			});
		},
		
		solidGauge = function(ctl, data, stops, custOptions, config, callback, container) {
			var chart = {
				type : 'solidgauge',
				margin: [5, 0, -5, 0]
			};
			if (config.margin)
				chart.margin = config.margin;
			if (config.spacing)
				chart.spacing = config.spacing;

			var options = {
				chart : chart,
				title : {
					text : config.title,
					style : {
						font : font.title
					}
				},
				pane : {
					center : [ '50%', '85%' ],
					size : '140%',
					startAngle : -90,
					endAngle : 90,
					background : {
						backgroundColor : (Highcharts.theme && Highcharts.theme.background2) || '#EEE',
						innerRadius : '60%',
						outerRadius : '100%',
						shape : 'arc'
					}
				},
				tooltip : {
					enabled : false
				},
				// the value axis
				yAxis : {
					stops : stops,
					lineWidth : 0,
					minorTickInterval : null,
					tickPixelInterval : 400,
					tickWidth : 0,
					labels : {
						y : 12
					},
					min: config.min,
					max: config.max
				},
				plotOptions : {
					solidgauge : {
						dataLabels : {
							y : 5,
							borderWidth : 0,
							useHTML : true
						}
					}
				},
				credits: {
		            enabled: false
		        },
		        series: [{
		            name: config.name,
		            data: [data],
		            dataLabels: {
		                format: '<div style="text-align:center"><span style="font-size:25px;color:' +
		                    ((Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black') + '">{y}</span><br/>' +
		                       '<span style="font-size:12px;color:silver">' + config.unit + '</span></div>'
		            },
		            tooltip: {
		                valueSuffix: ' ' + config.unit
		            }
		        }]
			};
			
			var op = options;//Highcharts.merge(true, options, custOptions);
			console.group('[' + ctl.id + '] solidGauge chart');
			console.log('theme: ' + (config.theme || 'empty') + ', bg: ' + (config.bgStyle || 'empty'));
			console.log(op);
			console.groupEnd();
			container.highcharts(op, function(chart) {
				if (!chart.renderer.forExport) {
					container.data('chartData', chart.series[0].points[0]);
				}
			});
		},
		
		timeseries = function(ctl, data, custOptions, config, callback, container) {
			var options = {
				chart : {
					zoomType : 'x',
					margin: config.margin,
					spacing : config.spacing || [ 8, 5, 0, 0 ]
				},
				title : {
					text : config.title,
					style : {
						font : font.title
					}
				},
				subtitle : {
					text : config.subTitle,
					style : {
						font : font.subTitle
					}
				},
				exporting : config.exporting,
				credits : false,
				xAxis : {
					type : 'datetime',
					labels : {
						format : config.xFormat || ''
					}
				},
				yAxis : {
					labels : {
						text : config.yTitle
					},
					label : {
						format : config.yFormat || ''
					}
				},
				legend : {
					enabled : false
				},
				plotOptions : {
					area : {
						fillColor : {
							linearGradient : {
								x1 : 0,
								y1 : 0,
								x2 : 0,
								y2 : 1
							},
							stops : [ [ 0, Highcharts.getOptions().colors[0] ], [ 1, Highcharts.Color(Highcharts.getOptions().colors[0]).setOpacity(0).get('rgba') ] ]
						},
						marker : {
							radius : 2
						},
						lineWidth : 1,
						states : {
							hover : {
								lineWidth : 1
							}
						},
						threshold : null,
						events : {
							click : function(event) {
								// console.log(event)
								if ($.isFunction(callback))
									callback({
										TIME : new Date(event.point.category).format(),
										VALUE : event.point.y
									});
							}
						}
					}
				},
				tooltip : {
					xDateFormat : '', // '%Y-%m-%d %H:%M:%S'
					pointFormat : '<b>{point.y}</b> ' + config.unit
				},
				series : [ {
					type : 'area',
					name : config.unit,
					data : data
				} ]
			};
			
			var op = Highcharts.merge(true, options, custOptions);
			console.group('[' + ctl.id + '] timeseries chart');
			console.log('theme: ' + (config.theme || 'empty') + ', bg: ' + (config.bgStyle || 'empty'));
			console.log(op);
			console.groupEnd();
			container.highcharts(op, function(chart) {
				if (!chart.renderer.forExport) {
					container.data('chartData', chart.series[0]);
				}
			});
		},
		
		pyramid = function(ctl, data, custOptions, config, callback, container) {
			var options = {
		        chart: {
					type : 'pyramid',
					margin : config.margin || [ 30, 0, 8, 0 ],
					marginRight : (config.showLabel ? container.width() / 3 : 0),
					spacing : config.spacing || [ 8, 0, 0, 0 ],
					options3d : {
						enabled : config.depth > 0,
						alpha : config.alpha,
						beta : config.beta
					},
				},
				title : {
					text : config.title,
					style : {
						font : font.title
					}
				},
				subtitle : {
					text : config.subTitle,
					style : {
						font : font.subTitle
					}
				},
				exporting : config.exporting,
				credits : false,
		        plotOptions: {
		            series: {
		                dataLabels: {
		                    enabled: config.showLabel,
		                    format: '{point.name}',
		                    color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black',
		                    softConnector: true
		                },
		                events : {
		                	click : function(event) {
		                		if ($.isFunction(callback))
		                			callback({
		                				NAME: event.point.name,
		                				VALUE: event.point.y
		                			});
		                	}
		                }
		            },
		            pyramid : {
		            	depth: config.depth
		            }
		        },
		        legend: {
		            enabled: false
		        },
				tooltip : {
					pointFormat : config.name + ': <b>{point.y}</b> ' + config.unit
				},
		        series: [{
		            name: config.name,
		            data: data
		        }]
		    };
			
			var op = Highcharts.merge(true, options, custOptions);
			console.group('[' + ctl.id + '] pyramid chart');
			console.log('theme: ' + (config.theme || 'empty') + ', bg: ' + (config.bgStyle || 'empty'));
			console.log(op);
			console.groupEnd();
			container.highcharts(op, function(chart) {
				if (!chart.renderer.forExport) {
					container.data('chartData', chart.series[0]);
				}
			});
		},
		
		funnel = function(ctl, data, custOptions, config, callback, container) {
			var options = {
		        chart: {
		            type: 'funnel',
		            margin: config.margin || [30, 0, 8, 0],
		            marginRight: (config.showLabel ? container.width()/3 : 0),
					spacing : config.spacing || [ 8, 0, 0, 0 ],
					options3d : {
						enabled : config.depth > 0,
						alpha : config.alpha,
						beta : config.beta
					}
		        },
				title : {
					text : config.title,
					style : {
						font : font.title
					}
				},
				subtitle : {
					text : config.subTitle,
					style : {
						font : font.subTitle
					}
				},
				exporting : config.exporting,
				credits : false,
		        plotOptions: {
		            series: {
		                dataLabels: {
		                    enabled: config.showLabel,
		                    format: '<b>{point.name}</b> ({point.y})',
		                    color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black',
		                    softConnector: true
		                },
		                neckWidth: '30%',
		                neckHeight: '25%',
		                events : {
		                	click : function(event) {
		                		//console.log(event);
		                		if ($.isFunction(callback))
		                			callback({
		                				NAME: event.point.name,
		                				VALUE: event.point.y
		                			});
		                	}
		                }
		            },
		            funnel : {
		            	depth: config.depth
		            }
		        },
				tooltip : {
					pointFormat : config.name + ': <b>{point.y}</b> ' + config.unit
				},
		        legend: {
		            enabled: false
		        },
		        series: [{
		            name: config.name,
		            data: data
		        }]
		    };
			
			var op = Highcharts.merge(true, options, custOptions);
			console.group('[' + ctl.id + '] funnel chart');
			console.log('theme: ' + (config.theme || 'empty') + ', bg: ' + (config.bgStyle || 'empty'));
			console.log(op);
			console.groupEnd();
			container.highcharts(op, function(chart) {
				if (!chart.renderer.forExport) {
					container.data('chartData', chart.series[0].data);
				}
			});
		};
    
		return {
			draw : function(ctl, chartData, customOptions, config, callback, container) {
				Highcharts.setOptions(defaultOptions);
				try {
					//Highcharts.setOptions(defaultOptions);
					var themeName = config.theme || 'empty', bgName = config.bgStyle || 'empty';
					var options = Highcharts.merge(true, {}, Theme[themeName], Bg[bgName], customOptions || {}, defaultOptions);
					// console.log(options);
					// container.empty();

					// console.log(t);
					if (config.type == 1 || config.type == 3 || config.type == 5 || config.type == 7 || config.type == 11) {
						if ($.type(chartData) !== 'array') {
							// $F.err('Ctls - chart', '不符合规则的数据，必须是ARRAY');
							return;
						}
						// console.log(chartData);
						// console.log('xCol:' + config.xCol + ", transCol:" + config.transCol + ", dataCol:" + config.dataCol);
						var i, v, n, k, categories = [], series = [], data;
						try {
							data = $PublicFun.toTransArray(chartData, [ config.transCol ], config.xCol, config.dataCol);
						}catch(e) {
							$F.err('Chart - draw', '数据交叉失败，请检查数据源');
							return;
						}
						//console.log(data);
						for (i = 1; i < data[0].length; i++) {
							categories.push(data[0][i]);
						}
						//console.log(categories);
						
						for (i = 1; i < data.length; i++) {
							v = data[i];
							k = [];
							for (n = 0; n < categories.length; n++) {
								k.push(v[n + 1] || 0);
							}
							if (container.data('chartData')) {
								if (container.data('chartData').length > i) {
									container.data('chartData')[i-1].update({
										data: k
									})
								}
							} else {
								series.push({
									name : v[0],
									data : k
								})
							}
						}
						
						if (! container.data('chartData')) {
							if (config.type == 1) {
								// 折线图
								line(ctl, categories, series, options, config, callback, container);
							} else if (config.type == 3){
								// 柱状图
								column(ctl, categories, series, options, config, callback, container);
							} else if (config.type == 5) {
								// 三轴对比图
								if (series.length < 2) {
									$F.err('Ctls - chart', '双Y轴的数据队列至少必须是两个');
									return;
								}
								lineColumn(ctl, categories, series, options, config, callback, container);
							} else if (config.type == 7) {
								// 条状图
								bar(ctl, categories, series, options, config, callback, container);
							} else if (config.type == 11) {
								// 混合图
								fixedPlacement(ctl, categories, series, options, config, callback, container);
							}
						}
					} else if (config.type == 2 || config.type == 8 || config.type == 9) {
						if (chartData.length == 0) {
							// $F.err('Ctls - chart', '不符合规则的数据，必须是ARRAY');
							return;
						}
						var data = [];
						$.each(chartData, function(i, v) {
							if (v[0] == config.slice) {
								data.push({
									name : v[0],
									y : v[1],
									sliced : true,
									selected : true
								});
							} else
								data.push([ v[0], v[1] ]);
						})
						
						if (container.data('chartData')) {
							// 已绘制图表，更新数据
							container.data('chartData').update({
								data : data
							})
						} else {
							if (config.type == 2) {
								// 饼图
								pie(ctl, data, options, config, callback, container);
							} else if (config.type == 8) {
								// 锥形图
								pyramid(ctl, data, options, config, callback, container);
							} else if (config.type == 9) {
								// 漏斗图
								funnel(ctl, data, options, config, callback, container);
							}
						}
					} else if (config.type == 4 || config.type == 10) {
						// 圆表图，半圆表
						if (container.data('chartData')) {
							// 已绘制图表，更新数据
							container.data('chartData').update(chartData)
						} else {
							// 未绘制图表
							if (config.type == 4) {
								// 圆表图
								var bands = [], sec, f = config.min, t;
								if (config.section.length == 0) {
									bands.push({
										from: f,
										to: config.max,
										color: '#55BF3B'
									})
								} else {
									var currentColor = '#55BF3B';
									$.each(config.section, function(i, v) {
										sec = v.split('#');
										if (sec.length > 1) {
											bands.push({
												from: f,
												to: sec[0],
												color: currentColor
											})
											f = sec[0];
											currentColor = '#' + sec[1];
										}
									})
									bands.push({
										from: f,
										to: config.max,
										color: currentColor
									})
								}
								gauges(ctl, chartData, bands, options, config, callback, container);
							} else {
								// 半圆图
								var bands = [], sec;
								$.each(config.section, function(i, v) {
									sec = v.split('#');
									if (sec.length > 1) {
										bands.push([sec[0], '#' + sec[1]])
									}
								})
								if (bands.length == 0)
									bands =  [[ 0.1, '#55BF3B' ], [ 0.5, '#DDDF0D' ], [ 0.9, '#DF5353' ]];
								solidGauge(ctl, chartData, bands, options, config, callback, container);
							}
						}
					} else if (config.type == 6) {
						// 时间线缩放图
						if (chartData.length == 0) {
							$F.err('Ctls - chart', '不符合规则的数据，必须是ARRAY');
							return;
						}
						var data = [], ds;
						for (i = 0; i < chartData.length; i++) {
							ds = chartData[i][config.xCol] + ' GMT';
							//console.log(ds);
							data.push([ Date.parse(ds), chartData[i][config.dataCol] ]);
						}
						
						if (container.data('chartData')) {
							// 已绘制图表，更新数据
							container.data('chartData').update({
								data : data
							})
						} else {
							timeseries(ctl, data, options, config, callback, container);
						}
					}
				} catch(e) {
					$F.err('Chart - darw', e);
				}
			}
		}
	})
} catch (e) {
	console.error(e);
}
